package com.example.vdfandroidproject;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

public class SplashActivity extends Activity
{
	private static final int STOPSPLASH = 0;

	/**
	 * Default duration for the splash screen (milliseconds)
	 */
	private static final long SPLASHTIME = 2000;

	/**
	 * Handler to close this activity and to start automatically {@link LoginActivity}
	 * after <code>SPLASHTIME</code> seconds.
	 */
	private final transient Handler splashHandler = new Handler()
	{
		@Override
		public void handleMessage(Message msg)
		{
			if (msg.what == STOPSPLASH)
			{
				final Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
				startActivity(intent);
				finish();
			}

			super.handleMessage(msg);
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);
		TextView tv = (TextView)this.findViewById(R.id.textViewSplashScreen);
		if(tv != null && tv instanceof TextView){
			tv.setText(R.string.app_name);
			tv.setTextColor(Color.WHITE);
		}
		final Message msg = new Message();
		msg.what = STOPSPLASH;
		splashHandler.sendMessageDelayed(msg, SPLASHTIME);
	}
}